package com.reyco1.medusa.display.container
{
	import com.reyco1.medusa.display.SmartSprite;
	
	import flash.display.DisplayObject;
	import flash.events.Event;
	
	public class Container extends SmartSprite
	{
		private   var _gap:Number 	 = 0;
		protected var _width:Number  = 0;
		protected var _height:Number = 0;
		
		public function Container()
		{
			super();
		}
		
		public function invalidate():void
		{
			startRender();
		}
		
		override protected function onRender():void
		{
			stopRender();
			build();
		}
		
		protected function build():void
		{			
		}
		
		override public function addChild(child:DisplayObject):DisplayObject
		{
			super.addChild(child);
			child.addEventListener(Event.RESIZE, handleChildResize);
			build();
			return child;
		}
		
		override public function addChildAt(child:DisplayObject, index:int):DisplayObject
		{
			super.addChildAt(child, index);
			child.addEventListener(Event.RESIZE, handleChildResize);
			build();
			return child;
		}
		
		override public function removeChild(child:DisplayObject):DisplayObject
		{
			super.removeChild(child);
			child.removeEventListener(Event.RESIZE, handleChildResize);
			build();
			return child;
		}
		
		override public function removeChildAt(index:int):DisplayObject
		{
			var child:DisplayObject = super.removeChildAt(index);
			child.removeEventListener(Event.RESIZE, handleChildResize);
			build();
			return child;
		}
		
		/* handlers */
		
		private function handleChildResize(e:Event):void
		{
			build();
		}
		
		/* properties */

		public function get gap():Number
		{
			return _gap;
		}

		public function set gap(value:Number):void
		{
			_gap = value;
			invalidate();
		}

		override public function get width():Number
		{
			return _width;
		}

		override public function get height():Number
		{
			return _height;
		}

	}
}